﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Celltest
{
    
    class Program
    {
        //public ConsoleKeyInfo keyinfo = Console.ReadKey(true);
        public const int Timelimit = 10000;
        public const bool quit = false;
        static void Main(string[] args)
        {
            
            //Console.Title = "Code Page 437: MS-DOS ASCII Characters";
            
            //ACRII();
            MainLoop();
            Console.ReadKey();
        }

        /// <summary>
        /// The main gameloop
        /// </summary>
        static ConsoleKeyInfo keyinfo()
        {
            return Console.ReadKey(true);
        }

        static void MainLoop()
        {
            GUI gui = new GUI();
            Cell cell = new Cell();
            int elapsedMilliseconds = 0;
            int totalMilliseconds = Timelimit * 1000;
            const int INTERVAL = 100;
            Position Playerpos = new Position(5,5);

            Position oldpos = Playerpos;


            cell.MakeCell(Console.WindowWidth / 2, Console.WindowHeight - 2);
            while (elapsedMilliseconds < totalMilliseconds && !quit)
            {
                // Sleep for a short period
                
                //Console.Clear();
                elapsedMilliseconds += INTERVAL;
                
                
                gui.WriteAt(1, Playerpos);
                
                if(keyinfo().Key == ConsoleKey.A)
                {
                    Playerpos.X-= 2;
                    gui.MakeStep(1,oldpos,Playerpos);
                }
                if (keyinfo().Key == ConsoleKey.D)
                {
                    Playerpos.X += 2;
                }
                if(keyinfo().Key == ConsoleKey.S)
                {
                    Playerpos.Y += 2;
                }
                if(keyinfo().Key == ConsoleKey.W)
                {
                    Playerpos.Y -= 2;
                }
                System.Threading.Thread.Sleep(INTERVAL);
                oldpos = Playerpos;
                /*** Update the screen and handle input here! ***/
            }

            Console.WriteLine("Game over!");
        }
        static void ACRII()
        {
            Console.WriteLine();
            for (byte b = 0; b < byte.MaxValue; b++)
            {
                char c = Encoding.GetEncoding(437).GetChars(new byte[] { b })[0];
                switch (b)
                {
                    case 8: // Backspace
                    case 9: // Tab
                    case 10: // Line feed
                    case 13: // Carriage return
                        c = '.';
                        break;
                }

                Console.Write("{0:000} {1}   ", b, c);

                // 7 is a beep -- Console.Beep() also works
                if (b == 7) Console.Write(" ");

                if ((b + 1) % 4 == 0)
                    Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}
